package com.example.myapplication4;

import android.app.AlertDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    EditText user_name;
    EditText user_code;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        user_name=(EditText) findViewById(R.id.editText);
        user_code=(EditText) findViewById(R.id.editText1);
        Button button=(Button)findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String accounts=user_name.getText().toString();
                String passwords=user_code.getText().toString();
                if(accounts.equals("admin")&&passwords.equals("admin")){

                    Intent intent=new Intent(MainActivity.this,SuccessActivity.class);
                    intent.putExtra("name",user_name.getText().toString());
                    intent.putExtra("code",user_code.getText().toString());
                    startActivity(intent);
                }else{
                    AlertDialog.Builder dlgAlert = new AlertDialog.Builder(MainActivity.this);

                    dlgAlert.setMessage("用户名或密码错误");

                    dlgAlert.setTitle("Error Message！！！");

                }
            }
        });
    }
}